package com.work.music.dao;

import com.work.music.entity.MusicPhonecode;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface MusicPhonecodeMapper {
    @Delete({
        "delete from music_phonecode",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into music_phonecode (phone, yzcode, ",
        "type, addtime, ",
        "addip)",
        "values (#{phone,jdbcType=VARCHAR}, #{yzcode,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=INTEGER}, #{addtime,jdbcType=TIMESTAMP}, ",
        "#{addip,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(MusicPhonecode record);

    @Select({
        "select",
        "id, phone, yzcode, type, addtime, addip",
        "from music_phonecode",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="yzcode", property="yzcode", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    MusicPhonecode selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, phone, yzcode, type, addtime, addip",
        "from music_phonecode"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="yzcode", property="yzcode", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    List<MusicPhonecode> selectAll();

    @Update({
        "update music_phonecode",
        "set phone = #{phone,jdbcType=VARCHAR},",
          "yzcode = #{yzcode,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=INTEGER},",
          "addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(MusicPhonecode record);
}